package com.kehutong.house.app;

import com.kehutong.house.entity.Community;
import com.kehutong.house.entity.ParkingClassify;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.Pool;
import org.coraframework.orm.jdbc.JdbcSession;
import org.coraframework.util.Objects;

import java.util.List;

/**
 * 车位分类信息
 */
@MvcAction
@ReqMapping("/kht-bin/basic/parking/classify")
public class ParkingClassifyAction {

    @Inject
    private JdbcSession jdbcSession;

    @ReqMapping("/list")
    public Object getParkingClassify(JSONObject jsonObject) {
        String communityNo = jsonObject.getString("communityNo");
        if(Objects.isBlank(communityNo)){
            return Result.error(0, "小区编号不能为空");
        }
        Community community = Pool.get(Community.class, communityNo);
        if (Objects.isNull(community)) {
            return Result.error(0, "请选择小区管理中创建的小区");
        }
        List<ParkingClassify> parkingClassifyList = jdbcSession.findArray(ParkingClassify.class)
                .eq(jsonObject, "communityNo", "level", "pid")
                .like(jsonObject,"name")
                .eq("deleted", false)
                .order("name", "ASC")
                .exe();
        return Result.success(parkingClassifyList);
    }
}
